package service;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import common.kit.PageSql;
import model.Staff;
import model.Station;
import model.SysetemParams;

public class SysetemParamsService extends BaseService {

	public Page<Record> getPage(Kv kv , Integer pageNumber , Integer pageSize) {
		String select = " tsp.id,tsp.velocityFieldCoefficient,tsp.kValue,tsp.lambda,ts.name " ;
	    PageSql pageSql = PageSql.bySelect( kv , select ) ;
	    pageSql.from(" t_sysetem_params tsp ") ;
	    pageSql.join(" t_station ts " , " ts.id = tsp.stationId ") ;
	    pageSql.join(" t_company tc " , " tc.id = ts.companyId ") ;
		pageSql.setEqualCondition("tsp.stationId") ; //点位	 
	    pageSql.orderBy(" tsp.createTime DESC ");
		return pageSql.paginate( pageNumber , pageSize) ;
	}

	public Ret save(SysetemParams sysetemParams , Station station , Staff staff) {
	    SysetemParams ex = SysetemParams.dao.findFirstByStationId(station.getId());
	    if(null == ex){
	    	sysetemParams.setStationId(station.getId());
	        sysetemParams.save();
	    }else{
	    	sysetemParams.setId(ex.getId());
	        sysetemParams.update() ;
	    }
	    station.setStaffId(staff.getId());
	    station.update() ;
	    return ok() ;
	}
}
